define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'userhome2/index' + location.search,
                    add_url: 'userhome2/add',
                    edit_url: 'userhome2/edit',
                    //del_url: 'userhome/del',
                    multi_url: 'userhome2/multi',
                    import_url: 'userhome2/import',
                    table: 'userhome',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        //{field: 'pid', title: __('Pid')},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        //{field: 'password', title: __('Password'), operate: 'LIKE'},
                        //{field: 'zfpwd', title: __('Zfpwd'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'birthday', title: __('Birthday'), operate:false, addclass:'datetimerange', autocomplete:false},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'vouchers', title: __('Vouchers'), operate:'BETWEEN'},
                        {field: 'bean', title: __('Bean')},
                        //{field: 'wxopenid', title: __('Wxopenid'), operate: 'LIKE'},
                        //{field: 'qqopenid', title: __('Qqopenid'), operate: 'LIKE'},
                        //{field: 'zfbopenid', title: __('Zfbopenid'), operate: 'LIKE'},
                        {field: 'is_renzheng', title: __('Is_renzheng'), searchList: {"1":__('Is_renzheng 1'),"2":__('Is_renzheng 2'),"3":__('Is_renzheng 3')}, formatter: Table.api.formatter.normal},
                        //{field: 'token', title: __('Token'), operate: 'LIKE'},
                        {field: 'spend', title: __('Spend'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                //commonSearch: false,//通用搜索
                showToggle: false,//显示隐藏列可以快速切换字段列的显示和隐藏，如果不需要此功能，可以设置showColumns: false，如果想要表格中的字段列默认隐藏可以设置字段属性visible: false即可默认隐藏
                showColumns: false,//导出按钮默认将导出整个表的所有行
                showExport: false,//导出excel
                search:false,//快速搜索
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});